<?php
/**
 * 表单中autosearch类  特别说明：所有带name或no为基本信息使用，不需要过滤已删除记录
 * @copyright   2011 友拓软件友拓通
 * @category   	通用
 * @package  	Action 
 * @version 	2011-03-25
 * @author 		黄明兴
 */
class AutoCompletePublicAction extends Action {
	
	protected $where 	= ' 1 ';
	protected $term  	= '';
	protected $limit 	= '0,20';
	protected $result 	= array();
	
	/// 构造函数
	public function __construct() {	 			
		$this->term 	= trim($_POST['term']); 
		$where 			= trim($_POST['where']);
		if ($where && $where!='undefined') $this->where .= ' and '.urldecode($where);
	}
	
	private function getWhere($field){
		if($this->term){
			$this->where .= ' and '.$field.' like \'%'.$this->term.'%\'';
		}
		return $this->where;
	}
	
	/// 析构函数
	public function __destruct() {
		foreach ($this->result as &$value) {
			foreach ($value as &$value2) {
				$value2 = htmlspecialchars_decode($value2);
			}
		}
		echo json_encode($this->result);
	}
	
	/// 语言包模块
	public function langModule(){
		$this->result	= M('Lang')->where($this->getWhere('module'))->order('module')->group('module')->limit($this->limit)->field('id as id,module as value')->select();
	}
	public function langModuleForClient(){
		$where			= $this->getWhere('lang_value_'.LANG_SET);
		$module			= M('Lang')->field('module')->group('module')->select();
		foreach($module as $val){
			$arr[]		= 'module_'.$val['module'];
		}
		$where			.=" and lang_key in ('".@implode("','",$arr)."')"; 
		$this->result	= M('Lang')->field('substr(lang_key,8) as id,lang_value_'.LANG_SET.' as value')->where($where)->order('lang_value_'.LANG_SET.' desc')->select();

	}
	/// 颜色编号
	public function colorNo(){
		$this->result = M('Color')->where($this->getWhere('color_no'))->order('color_no desc')->limit($this->limit)->field('id as id ,color_no as value')->select();
	}
	
	public function colorName(){
		$this->result = M('Color')->where($this->getWhere('color_name'))->order('color_name desc')->limit($this->limit)->field('id as id,color_name as value')->select();
	}
	
	/// 尺码编号
	public function sizeNo(){
		$this->result = M('Size')->where($this->getWhere('size_no'))->order('size_no desc')->limit($this->limit)->field('id as id ,size_no as value')->select();
	}
	///尺码名称
	public function sizeName(){
		$this->result = M('Size')->where($this->getWhere('size_name'))->order('size_name desc')->limit($this->limit)->field('id as id,size_name as value')->select();
	}
	
	///国家名称--国家列表
	public function countryName(){
		$where			= $this->getWhere('district_name').' and parent_id=0';
		$this->result	= M('District')->where($where)->order('district_name ')->limit($this->limit)->field('id as id,district_name as value')->select();
	}
	
	///国家代码
	public function abbrDistrictName(){
		$where			= $this->getWhere('abbr_district_name').' and parent_id=0 and abbr_district_name is not null';
		$this->result	= M('District')->where($where)->order('abbr_district_name ')->limit($this->limit)->field('id as id,abbr_district_name as value')->select();
	}
	
	///城市名称--国家列表
	public function cityName(){
		$where			= $this->getWhere('district_name').' and parent_id>0';
		$this->result	= M('District')->where($where)->order('district_name ')->limit($this->limit)->field('id as id,district_name as value')->select();
	}
	///公司名称
	public function companyName(){
		$this->result	= M('Basic')->where($this->getWhere('basic_name'))->order('basic_name desc')->limit($this->limit)->field('id as id,basic_name as value')->select();
	}
	///仓库编号
	public function warehouseNo(){
		$this->result	= M('Warehouse')->where($this->getWhere('w_no'))->order('w_no desc')->limit($this->limit)->field('id as id,w_no as value')->select();
	}
	///仓库名称
	public function warehouseName(){
		$this->result	= M('Warehouse')->where($this->getWhere('w_name'))->order('w_name desc')->limit($this->limit)->field('id as id,w_name as value')->select();
	}
	///部门编号
	public function departmentNo(){
		$this->result	= M('Department')->where($this->getWhere('department_no'))->order('department_no desc')->limit($this->limit)->field('id as id,department_no as value')->select();
	}
	///部门名称
	public function departmentName(){
		$this->result	= M('Department')->where($this->getWhere('department_name'))->order('department_name desc')->limit($this->limit)->field('id as id,department_name as value')->select();
	}
	///职务编号
	public function positionNo(){
		$this->result	= M('Position')->where($this->getWhere('position_no'))->order('position_no desc')->limit($this->limit)->field('id as id,position_no as value')->select();
	}
	///职务名称
	public function positionName(){
		$this->result	= M('Position')->where($this->getWhere('position_name'))->order('position_name desc')->limit($this->limit)->field('id as id,position_name as value')->select();
	}
	///员工编号
	public function employeeNo(){
		$this->result	= M('Employee')->where($this->getWhere('employee_no'))->order('employee_no desc')->limit($this->limit)->field('id as id,employee_no as value')->select();
	}
	///员工名称
	public function employeeName(){
		$this->result	= M('Employee')->where($this->getWhere('employee_name'))->order('employee_name desc')->limit($this->limit)->field('id as id,employee_name as value')->select();
	}
	///银行简称
	public function accountName(){
		$this->result	= M('Bank')->where($this->getWhere('account_name').' and to_hide=1 ')->order('account_name desc')->limit($this->limit)->field('id as id,account_name as value')->select();
	}
	///银行名称
	public function bankName(){
		$this->result	= M('Bank')->where($this->getWhere('bank_name'))->order('bank_name desc')->limit($this->limit)->field('id as id,bank_name as value')->select();
	}
	///银行名称
	public function bank(){ 
		$this->result	= M('Bank')->where($this->getWhere('bank_name').' and to_hide=1 ')->order('bank_name desc')->limit($this->limit)->field('id as id,bank_name as value')->select();
///		$this->result	= M('Bank')->where('1 and to_hide=1 ')->limit($this->limit)->field('id as id,bank_name as value')->select();
	}
	/// 银行帐号
	public function accountFundStat() {	 
		$array[-1]	=	array( 
								'id'=>-1,
								'value'=>'现金',
								);
		$array[-2]	=	array( 
								'id'=>-2,
								'value'=>'支票',
								);
		$data	= M('Bank')->where(' 1 and to_hide=1 ')->limit($this->limit)->field('id as id,bank_name as value')->select(); 
		$rs		= array_merge($array,$data); 
		$this->result	=	$rs;
	}
	
	
	///支出类型名称
	public function payClassName(){
		$this->result	= M('PayClass')->where($this->getWhere('pay_class_name'))->order('pay_class_name desc')->limit($this->limit)->field('id as id,pay_class_name as value')->select();
	}
	///支出类型
	public function OutLay(){
		$this->result	= M('PayClass')->where($this->getWhere('pay_class_name').' and pay_type=1 and to_hide=1 ')->order('pay_class_name desc')->limit($this->limit)->field('id as id,pay_class_name as value')->select();
	}
	///收入类型
	public function IncomeLay(){
		$this->result	= M('PayClass')->where($this->getWhere('pay_class_name').' and pay_type=2 and to_hide=1 ')->order('pay_class_name desc')->limit($this->limit)->field('id as id,pay_class_name as value')->select();
	}
	///用户名称
	public function userName(){
		$this->result	= M('User')->where($this->getWhere('user_name'))->order('user_name desc')->limit($this->limit)->field('id as id,user_name as value')->select();
	}
	/// 菜单名称
	public function node(){
		$this->result	= M('Node')->where($this->getWhere('title'))->limit($this->limit)->field('id as id,title as value')->select();
	}
	///产品属性名称
	public function propertiesName(){
		$table	=	'properties';
		$field	=	'properties_name';
		$where	=	$this->getWhere($field);
		$this->getList($table,$field,$where); 
	}
	///产品属性编号
	public function propertiesNo(){
		$table	=	'properties';
		$field	=	'properties_no';
		$where	=	$this->getWhere($field);
		$this->getList($table,$field,$where); 
	}
	///产品属性值名称
	public function pvName(){
		$table	=	'properties_value';
		$field	=	'pv_name';
		$where	=	$this->getWhere($field);
		$this->getList($table,$field,$where); 
	}
	
///	public function pv(){
///		$table	=	'properties_value';
///		$field	=	'pv_name';
///		$where	=	$this->getWhere($field); 
///		$this->getList($table,$field,$where); 
///	}
	///产品属性值编号
	public function pvNo(){
		$table	=	'properties_value';
		$field	=	'pv_no';
		$where	=	$this->getWhere($field); 
		$this->getList($table,$field,$where); 
	}
	///一级类别名称
	public function productClass1Name(){
		$table	=	'product_class';
		$field	=	'class_name'; 
		$where	=	$this->getWhere($field); 
		$where	.=	' and class_level=1 '; 
		$this->getList($table,$field,$where); 
	}
	///二级类别名称
	public function productClass2Name(){
		$table	=	'product_class';
		$field	=	'class_name'; 
		$where	=	$this->getWhere($field); 
		$where	.=	' and class_level=2 '; 
		$this->getList($table,$field,$where); 
	}
	///三级类别名称
	public function productClass3Name(){
		$table	=	'product_class';
		$field	=	'class_name'; 
		$where	=	$this->getWhere($field); 
		$where	.=	' and class_level=3 '; 
		$this->getList($table,$field,$where); 
	}
	///四级类别名称
	public function productClass4Name(){
		$table	=	'product_class';
		$field	=	'class_name'; 
		$where	=	$this->getWhere($field); 
		$where	.=	' and class_level=4 '; 
		$this->getList($table,$field,$where); 
	}
	
	///产品编号
	public function barcode(){
		$table	=	'barcode';
		$field	=	'barcode_no';
		$where	=	$this->getWhere($field); 
		$this->getList($table,$field,$where); 
	} 
	///产品编号
	public function productNo(){
		$table	=	'product';
		$field	=	'product_no';
		$where	=	$this->getWhere($field); 
		if (getUser('role_type')==4 && C('product_factory')==1) {
			$where .= ' and factory_id='.intval(getUser('company_id'));
		}
		$this->getList($table,$field,$where); 
	} 
	///产品名称 
	public function productName(){
		$table	=	'product';
		$field	=	'product_name';
		$where	=	$this->getWhere($field); 
		if (getUser('role_type')==4 && C('product_factory')==1) {
			$where .= ' and factory_id='.intval(getUser('company_id'));
		}
		$this->getList($table,$field,$where); 
	}
	///客户编号 
	public function clientNo(){
		$where		  = $this->getWhere('comp_no').' and comp_type=1';
		$this->result = M('Company')->where($where)->limit($this->limit)->field('id as id ,comp_no as value')->select();
	}
	///客户名称
	public function clientName(){
		$where		  = $this->getWhere('comp_name').' and comp_type=1';
		$this->result = M('Company')->where($where)->limit($this->limit)->field('id as id ,comp_name as value')->select();
	} 
	///厂家编号
	public function factoryNo(){
		$where		= $this->getWhere('comp_no').' and comp_type=2';
		if (getUser('role_type')==4) {
			$where .=' and id='.intval(getUser('company_id'));
		}
		$this->result = M('Company')->where($where)->limit($this->limit)->field('id as id ,comp_no as value')->select();
	}
	///厂家名称 
	public function factoryName(){
		$where		  = $this->getWhere('comp_name').' and comp_type=2';
		if (getUser('role_type')==4) {
			$where .=' and id='.intval(getUser('company_id'));
		}
		$this->result = M('Company')->where($where)->limit($this->limit)->field('id as id ,comp_name as value')->select();
	}
	///物流公司编号
	public function logisticsNo(){
		$where			= $this->getWhere('comp_no').' and comp_type=3';
		$this->result	= M('Company')->where($where)->limit($this->limit)->field('id as id,comp_no as value')->select();
	}
	///物流公司名称
	public function logisticsName(){
		$where			= $this->getWhere('comp_name').' and comp_type=3';
		$this->result	= M('Company')->where($where)->limit($this->limit)->field('id as id,comp_name as value')->select();
	}
	///其他往来单位编号
	public function otherCompanyNo(){
		$where			= $this->getWhere('comp_no').' and comp_type=4';
		$this->result	= M('Company')->where($where)->limit($this->limit)->field('id as id,comp_no as value')->select();
	}
	///其他往来单位名称
	public function otherCompanyName(){
		$where			= $this->getWhere('comp_name').' and comp_type=4';
		$this->result	= M('Company')->where($where)->limit($this->limit)->field('id as id,comp_name as value')->select();
	}
	///发票品名名称
	public function invoiceProductName(){
		$this->result	= M('InvoiceProduct')->where($this->getWhere('product_name'))->limit($this->limit)->field('id as id,product_name as value')->select();
	}
	///发票客户名称
	public function invoiceClientName(){
		$where			= $this->getWhere('company_name').' and comp_type=3';
		$this->result	= M('InvoiceCompany')->where($where)->limit($this->limit)->field('id as id,company_name as value')->select();
	}
	///发票客户税号
	public function invoiceClientTaxNo(){
		$where			= $this->getWhere('tax_no').' and comp_type=3';
		$this->result	= M('InvoiceCompany')->where($where)->limit($this->limit)->field('id as id,tax_no as value')->select();
	}
	///发票供应商
	public function invoiceCompanyName(){
		$where			= $this->getWhere('company_name').' and comp_type=2';
		$this->result	= M('InvoiceCompany')->where($where)->limit($this->limit)->field('id as id,company_name as value')->select();
	}
	///发票公司
	public function invoiceBasicName(){
		$where			= $this->getWhere('company_name').' and comp_type=1';
		$this->result	= M('InvoiceCompany')->where($where)->limit($this->limit)->field('id as id,company_name as value')->select();
	}
	/// 产品类别末级
	public function lastProductClass() {
		$model		 = D('ProductClassView');
		$class_level = C('PRODUCT_CLASS_LEVEL');
		if (C('PRODUCT_CLASS_LEVEL')==1) {
			$fkey	=	'a';
			$key	= 'a_id';
			$field	= 'a_class_name';
			$where	= 'a.id>0 and a.to_hide=1';
			$order	= 'a.class_no asc';
			if (strlen(trim($_GET['q']))>0){ 
				$where	.= ' and a.class_name like \'%'.$this->query_str.'%\' ';	
			}  
			unset($model->autocomplete['c'],$model->autocomplete['d']);
		}elseif (C('PRODUCT_CLASS_LEVEL')==2) {
			$fkey	=	'b';
			$key	= 'b_id';
			$field	= 'b_class_name';
			$before = 'b_before_field';
			$where	= 'b.id>0 and b.to_hide=1';
			$order	= 'b.class_no asc';
			if (strlen(trim($_GET['q']))>0){ 
				$where	.= ' and b.class_name like \'%'.$this->query_str.'%\' ';	
			}  
			unset($model->autocomplete['c'],$model->autocomplete['d']);
		}elseif (C('PRODUCT_CLASS_LEVEL')==3) {
			$fkey	=	'c';
			$key	= 'c_id';
			$field	= 'c_class_name';
			$before = 'c_before_field';
			$where	= 'c.id>0 and c.to_hide=1';
			$order	= 'c.class_no asc';
			if (strlen(trim($_GET['q']))>0){ 
				$where	.= ' and c.class_name like \'%'.$this->query_str.'%\' ';	
			}  
			unset($model->autocomplete['d']);
		}elseif (C('PRODUCT_CLASS_LEVEL')==4) {
			$fkey	=	'd';
			$key	= 'd_id';
			$field	= 'd_class_name';
			$before = 'd_before_field';
			$where	= 'd.id>0 and d.to_hide=1';
			$order	= 'd.class_no asc';
			if (strlen(trim($_GET['q']))>0){ 
				$where	.= ' and d.class_name like \'%'.$this->query_str.'%\' ';	
			} 
		}  
		$model->viewFields = $model->autocomplete;
		$data = $model->field($key.','.$field.','.$before)->limit($this->limit)->where('a.to_hide=1 and a.class_level=1 and '.$where)->order($order)->select();   
		foreach ($data as $key=>$row) 
		{
			if (C('PRODUCT_CLASS_LEVEL')>1){
				$info[$key] = array('id'=>$row[$fkey.'_id'],'value'=>$row[$fkey.'_before_field'].'->'.$row[$fkey.'_class_name']);
			}else{
				$info[$key] = array('id'=>$row[$fkey.'_id'],'value'=>$row[$fkey.'_before_field'].''.$row[$fkey.'_class_name']);	
			} 
		}   
		$this->result	=	$info;
	}
	
	/**
	 * 公用函数返回列表信息并且json化
	 *
	 * @param string $table
	 * @param string $field
	 * @return array
	 */
	public function getList($table,$field,$where){
    	$this->result = M($table)->where($where)->order($field.' desc')->limit('0,20')->field('id as id ,'.$field.' as value')->select();  
	}
	
	
	/**
	 * 以下所有方法为基本信息外调用，必须增加to_hide=1状态
	 *
	 */ 
	
	/// 币种
	public function currency(){
    	$this->result = M('Currency')->where($this->getWhere('currency_no').' and to_hide=1')->order('currency_no desc')->limit($this->limit)->field('id as id ,currency_no as value')->select();
	} 
	
	/// 角色
	public function role(){
    	$this->result = M('Role')->where($this->getWhere('role_name').' and to_hide=1')->order('role_name desc')->limit($this->limit)->field('id as id ,role_name as value')->select();
	}
	
	/// 用户
	public function user(){
    	$this->result = M('User')->where($this->getWhere('user_name').' and super_admin=0 and to_hide=1')->order('user_name desc')->limit($this->limit)->field('id as id ,user_name as value')->select();
	}
	/// 颜色名称
	public function epass(){
		$this->result = M('Epass')->where($this->getWhere('epass_no').' and to_hide=1')->order('epass_no desc')->limit($this->limit)->field('id as id ,epass_no as value')->select();
	}
	/// 颜色名称
	public function color(){
		$this->result = M('Color')->where($this->getWhere('color_name').' and to_hide=1')->order('color_name desc')->limit($this->limit)->field('id as id ,color_name as value')->select();
	}
	///员工名称
	public function employee(){
		$this->result	= M('Employee')->where($this->getWhere('employee_name').' and to_hide=1')->order('employee_name desc')->limit($this->limit)->field('id as id,employee_name as value')->select();
	}
	/// 尺码名称
	public function size(){
		$this->result = M('Size')->where($this->getWhere('size_name').' and to_hide=1')->order('size_name desc')->limit($this->limit)->field('id as id ,size_name as value')->select();
	}
	/// 产品类别
	public function productClass(){
		$this->result = M('ProductClass')->where($this->getWhere('class_name').' and to_hide=1')->order('class_name desc')->limit($this->limit)->field('id as id ,class_name as value')->select();
	}
	///城市名称
	public function city(){
		$where			= $this->getWhere('district_name').' and parent_id>0 and to_hide=1';
		$this->result	= M('District')->where($where)->order('district_name')->limit($this->limit)->field('id as id,district_name as value')->select();
	}
	
	///国家名称
	public function country(){
		$where			= $this->getWhere('district_name').' and parent_id=0 and to_hide=1';
		$this->result	= M('District')->where($where)->order('district_name')->limit($this->limit)->field('id as id,district_name as value')->select();
	}
	///一级类别
	public function productClass1(){
		$table	=	'product_class';
		$field	=	'class_name'; 
		$where	=	$this->getWhere($field); 
		$where	.=	' and class_level=1 and to_hide=1'; 
		$this->getList($table,$field,$where); 
	}
	///二级类别
	public function productClass2(){
		$table	=	'product_class';
		$field	=	'class_name'; 
		$where	=	$this->getWhere($field); 
		$where	.=	' and class_level=2 and to_hide=1'; 
		$this->getList($table,$field,$where); 
	}
	///三级类别
	public function productClass3(){
		$table	=	'product_class';
		$field	=	'class_name'; 
		$where	=	$this->getWhere($field); 
		$where	.=	' and class_level=3 and to_hide=1'; 
		$this->getList($table,$field,$where); 
	}
	///三级类别
	public function productClass4(){
		$table	=	'product_class';
		$field	=	'class_name'; 
		$where	=	$this->getWhere($field); 
		$where	.=	' and class_level=4 and to_hide=1'; 
		$this->getList($table,$field,$where); 
	}
	
	///公司名称
	public function company(){
		$where			= $this->getWhere('basic_name').' and to_hide=1';
		$this->result	= M('Basic')->where($where)->limit($this->limit)->field('id as id,basic_name as value')->select();
	}
	/// 部门
	public function department(){
		$where			= $this->getWhere('department_name').' and to_hide=1';
		$this->result	= M('Department')->where($where)->limit($this->limit)->field('id as id,department_name as value')->select();
	}
	/// 职务
	public function position(){
		$where			= $this->getWhere('position_name').' and to_hide=1';
		$this->result	= M('Position')->where($where)->limit($this->limit)->field('id as id,position_name as value')->select();
	}
	/// 产品属性
	public function properties(){
		$table	=	'properties';
		$field	=	'properties_name';
		$where	=	$this->getWhere($field).' and to_hide=1 ';  
		$this->getList($table,$field,$where); 
	}
	/// 产品
	public function product(){
		$where		  = $this->getWhere('product_no').' and to_hide=1';
		if (getUser('role_type')==4 && C('product_factory')==1) {
			$where .= ' and factory_id='.intval(getUser('company_id'));
		}
		$this->result = M('Product')->where($where)->order('product_no desc')->limit($this->limit)->field('id as id ,product_no as value')->group('product_no desc')->select(); 
	}
	/// 产品可销售库存不为0
	public function productSale(){
		$where		  	= $this->getWhere('product_no').' and a.quantity>0 and b.to_hide=1'; 
		$info 			= M('sale_storage')->join(' as a left join product as b on a.product_id =b.id ')->group('b.product_no desc')->where($where)->order('b.product_no desc')->limit($this->limit)->field('a.product_id as id,b.product_no as value')->select();  
///		echo M('sale_storage')->getLastSql();
		$this->result	=	$info;
	}
	/// 产品实际库存不为0
	public function productReal(){
		$where		  	= $this->getWhere('product_no').' and a.quantity>0 and b.to_hide=1'; 
		$info 			= M('Storage')->join(' as a left join product as b on a.product_id =b.id ')->order('b.product_no desc')->group('b.product_no')->where($where)->limit($this->limit)->field('a.product_id as id,b.product_no as value')->select();  
///		echo M('sale_storage')->getLastSql();
		$this->result	=	$info;
	}
	/// 已订货未装柜完成产品
	public function orderProduct(){
		$where		  = $this->getWhere('product_no').' and detail_state<3 and product.id IS NOT NULL ';
		$this->result = M('OrderDetails')->join('product on(order_details.product_id=product.id)')->order('product.product_no desc')->where($where)->limit($this->limit)->field('product.id as id ,product.product_no as value')->group('product.product_no')->select();
	}
	///厂家名称 
	public function factory(){
		$where		  = $this->getWhere('comp_name').' and comp_type=2 and to_hide=1';
		if (getUser('role_type')==4) {
			$where .=' and id='.intval(getUser('company_id'));
		}
		$this->result = M('Company')->where($where)->order('comp_name desc')->limit($this->limit)->field('id as id ,comp_name as value')->select();
	}
	///厂家名称 
	public function client(){
		$where		  = $this->getWhere('comp_name').' and comp_type=1 and to_hide=1';
		if (getUser('role_type')==5) {
			$where .=' and id='.intval(getUser('company_id'));
		}
		$this->result = M('Company')->where($where)->order('comp_name desc')->limit($this->limit)->field('id as id ,comp_name as value')->select();
	}
	///物流公司
	public function logistics(){
		$where			= $this->getWhere('comp_name').' and comp_type=3 and to_hide=1';
		$this->result	= M('Company')->where($where)->order('comp_name desc')->limit($this->limit)->field('id as id,comp_name as value')->select();
	}
	/// 订单号
	public function orderNo(){
		$where		  = $this->getWhere('order_no');
		if (getUser('role_type')==4) {
			$where .= ' and factory_id='.intval(getUser('company_id'));
		}
		$this->result = M('Orders')->where($where)->limit($this->limit)->order('order_no desc')->field('id as id ,order_no as value')->select();
	}
	/// 装柜单号
	public function loadContainerNo(){
		$where		  = $this->getWhere('load_container_no');
		$this->result = M('LoadContainer')->where($where)->limit($this->limit)->order('load_container_no desc')->field('id as id ,load_container_no as value')->select();
	} 
	
	/// 集装箱号
	public function containerNo(){
		$where		  = $this->getWhere('container_no');
		$this->result = M('LoadContainer')->where($where)->limit($this->limit)->order('container_no desc')->field('id as id,container_no as value')->group('container_no')->select();
	}
	
	/// 销售
	public function saleOrderNo(){
		$where		  = $this->getWhere('sale_order_no').' ';
		$this->result = M('sale_order')->where($where)->limit($this->limit)->order('sale_order_no desc')->field('id as id ,sale_order_no as value')->select();
	}
	/// 发货
	public function deliveryNo(){
		$where		  = $this->getWhere('delivery_no').'  ';
		$this->result = M('delivery')->where($where)->limit($this->limit)->order('delivery_no desc')->field('id as id ,delivery_no as value')->select();
	}
	///配货
	public function preDeliveryNo(){
		$where		  = $this->getWhere('pre_delivery_no').'  ';
		$this->result = M('pre_delivery')->where($where)->limit($this->limit)->order('pre_delivery_no desc')->field('id as id ,pre_delivery_no as value')->select();
	} 
	///入库单号
	public function instockNo(){
		$where		 = $this->getWhere('instock_no');
		$this->result= M('Instock')->where($where)->limit($this->limit)->order('instock_no desc')->field('id as id,instock_no as value')->select();
	}
	///仓库
	public function warehouse(){
		$where		  = $this->getWhere('w_name').' and to_hide=1 and is_use=1';
		$this->result = M('Warehouse')->where($where)->limit($this->limit)->field('id as id,w_name as value')->select();
	}

	///入库集装箱号
	public function instockContainerNo(){
		$where		    = $this->getWhere('container_no');
		$this->result	= M('Instock')->where($where)->limit($this->limit)->field('id as id,container_no as value')->group('container_no')->select();
	} 
	///退货单号
	public function returnSaleOrderNo(){
		$where			= $this->getWhere('return_sale_order_no');
		$this->result	= M('ReturnSaleOrder')->where($where)->limit($this->limit)->order('return_sale_order_no desc')->field('id as id,return_sale_order_no as value')->select();
	}
	/// 调整单号
	public function adjustNo(){
		$where			= $this->getWhere('adjust_no');
		$this->result	= M('Adjust')->where($where)->limit($this->limit)->order('adjust_no desc')->field('id as id,adjust_no as value')->select();
	}
	/// 调拨单号
	public function transferNo(){
		$where			= $this->getWhere('transfer_no');
		$this->result	= M('Transfer')->where($where)->limit($this->limit)->order('transfer_no desc')->field('id as id,transfer_no as value')->select();
	}
	/// 期初库存单号
	public function initStorageNo(){
		$where			= $this->getWhere('init_storage_no');
		$this->result	= M('InitStorage')->where($where)->limit($this->limit)->order('init_storage_no desc')->field('id as id,init_storage_no as value')->select();
	}
	///退货产品
	public function returnProduct(){
		$where		  = $this->getWhere('product_no');
		$this->result = M('SaleOrderDetail')->join('product on(sale_order_detail.product_id=product.id)')->join('sale_order on (sale_order.id=sale_order_detail.sale_order_id)')->where($where)->limit($this->limit)->field('product.id as id ,product.product_no as value')->group('product.id')->select();
	}
	///订货产品颜色
	public function orderProductColor(){
		$this->result	= M('OrderDetails')->join('color on order_details.color_id=color.id')->where($this->getWhere('color_name'))->field('color_id as id,color_name as value')->group('id')->select();
	}
	///根据产品获得订货单
	public function orderNoByProduct(){
		$this->result	= M('Orders')->join('order_details on orders.id=order_details.orders_id')->where($this->getWhere('order_no'))->field('orders.id,orders.order_no as value')->group('id')->select();
	}
	///销售根据产品获取可销售库存的颜色
	public function saleroductColor(){
		$this->result	= M('SaleStorage')->join('color on sale_storage.color_id=color.id')->where($this->getWhere('color_name'))->field('color_id as id,color_name as value')->group('id')->select();
	}
	
	/// 尾箱库存
	public function lastStorageCapability(){
		$this->result = M('SaleStorage')->group('capability')->where($this->getWhere('capability').' and quantity>0')->field('capability as value')->order('id desc')->select();
	}
	/// 尾箱库存
	public function lastStorageDozen(){
		$this->result = M('SaleStorage')->group('dozen')->where($this->getWhere('dozen').' and quantity>0')->field('dozen as value')->order('id desc')->select();
	}
	///销售根据产品获取可销售库存的颜色
	public function saleroductSize(){
		$this->result	= M('SaleStorage')->join('size on sale_storage.size_id=size.id')->where($this->getWhere('size_name'))->field('size_id as id,size_name as value')->group('id')->select();
	}
	///订货产品规格
	public function orderProductSize(){
		$this->result	= M('OrderDetails')->join('size on order_details.size_id=size.id')->where($this->getWhere('size_name'))->field('size_id as id,size_name as value')->group('id')->select();
	}
	///发票厂家
	public function invoiceFactory(){
		$where			= $this->getWhere('company_name').' and comp_type=2 and to_hide=1';
		$this->result	= M('InvoiceCompany')->where($where)->field('id as id,company_name as value')->select();
	}
	///发票公司
	public function invoiceCompany(){
		$where			= $this->getWhere('compang_name').' and comp_type=1 and to_hide=1';
		$this->result	= M('InvoiceCompany')->where($where)->field('id as id,company_name as value')->select();
	}
	///发票产品
	public function invoiceProduct(){
		///产品来源配置为 产品列表
		if(C('invoice.product_from')==1){
			///配置为 不显示产品号
			if(C('invoice.product')==2){
				$where			= $this->getWhere('product_name').' and to_hide=1';
				$this->result	= M('Product')->where($where)->field('id as id,product_name as value')->select();
			}else{
				$this->product();
			}
		}else{
			///配置为 不显示产品号
			if(C('invoice.product')==2){
				$where			= $this->getWhere('product_name').' and to_hide=1';
				$this->result	= M('InvoiceProduct')->where($where)->field('id as id,product_name as value')->select();
			}else{
				$where			= $this->getWhere('product_no').' and to_hide=1';
				$this->result	= M('InvoiceProduct')->where($where)->field('id as id,product_no as value')->select();
			}
		}
	}
	///发票产品名称 发票库存列表 使用
	public function invoiceStorageProductName(){
		$where				= $this->getWhere('product_name').' and to_hide=1';
		if(C('invoice.product_from')==1){
			$this->result	= M('Product')->where($where)->field('id as id,product_name as value')->select();
		}else{
			$this->result	= M('InvoiceProduct')->where($where)->field('id as id,product_name as value')->select();
		}
	}
	///进货发票号
	public function invoiceInInvoiceNo(){
		$this->result	= M('InvoiceIn')->where($this->getWhere('invoice_no'))->limit($this->limit)->field('id as id,invoice_no as value')->select();
	}
	///进发票 入库单
	public function invoiceInstockNo(){
		$where			= $this->getWhere('instock_no').' and invoice_state=1';
		$this->result	= M('Instock')->join('instock_detail on instock.id=instock_detail.instock_id')->where($where)->limit($this->limit)->field('instock.id as id,instock_no as value')->group('instock.id')->select();
	}
	///出发票 销售单
	public function invoiceSaleOrderNo(){
		$where			= $this->getWhere('sale_order_no').' and invoice_state=1';
		$this->result	= M('SaleOrder')->where($where)->limit($this->limit)->field('id as id,sale_order_no as value')->select();
	}
	///出发票 退货单
	public function invoiceReturnOrderNo(){
		$where			= $this->getWhere('return_sale_order_no').' and invoice_state=1';
		$this->result	= M('ReturnSaleOrder')->where($where)->limit($this->limit)->field('id as id,return_sale_order_no as value')->select();
	}
	///发票客户
	public function invoiceClient(){
		$where			= $this->getWhere('company_name').' and comp_type=3 and to_hide=1';
		$this->result	= M('invoice_company')->where($where)->limit($this->limit)->field('id as id,company_name as value')->select();
	}
	///出发票号
	public function invoiceOutInvoiceNo(){
		$this->result	= M('InvoiceOut')->where($this->getWhere('invoice_no'))->limit($this->limit)->field('id as id,invoice_no as value')->select();
	}
	/// 盘点单号
	public function stockTakeNo(){
		$where		  = $this->getWhere('stocktake_no');
		$this->result = M('Stocktake')->where($where)->limit($this->limit)->order('stocktake_no desc')->field('id as id ,stocktake_no as value')->select();
	}
	/// 盈亏单号
	public function profitandlossNo(){
		$where		  = $this->getWhere('profitandloss_no');
		$this->result = M('Profitandloss')->where($where)->limit($this->limit)->order('profitandloss_no desc')->field('id as id ,profitandloss_no as value')->select();
	}
	///产品颜色
	public function productColor(){
		$where		  = $this->getWhere('color_name');
		$this->result = M('ProductColor')->join('color on(product_color.color_id=color.id)')->where($where)->limit($this->limit)->field('color.id as id ,color.color_name as value')->select();
	}
	///产品尺码
	public function productSize(){
		$where		  = $this->getWhere('color_name');
		$this->result = M('ProductSize')->join('size on(product_size.size_id=size.id)')->where($where)->limit($this->limit)->field('size.id as id ,size.size_name as value')->select();
	}
	
	/// 属性名称+条形码(增加条形码的时候使用,设置规则)
	public function addBarcode() {
		///$data = M('Properties')->where($this->extend.$this->default_where)->findAllNotLtd(); 
///		$this->result['country']		= L('country_no');
///		$this->result['size_no']		= L('size_no');
///		$this->result['color_no']		= L('color_no');
///		$this->result['class_no']		= L('class_no');
///		$this->result['product_no']		= L('product_no');
///		$this->result['comp_no']		= L('fac_no');
///		$this->result['serial_no']		= L('water_no');
		$this->result	= array(
							array(
								'id'=>'country',
								'value'=> '国家编号'
							),
							array(
								'id'=>'size_no',
								'value'=> '尺码编号'
							),
							array(
								'id'=>'color_no',
								'value'=> '颜色编号'
							),
							array(
								'id'=>'class_no',
								'value'=> '类别编号'
							),
							array(
								'id'=>'product_no',
								'value'=> '产品编号'
							),
							array(
								'id'=>'comp_no',
								'value'=> '公司'
							),
							array(
								'id'=>'serial_no',
								'value'=> '流水号'
							)
							
		);
	}
}